package com.yanqu.road.entity.activity.twins.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TwinsConfig {

    private ActivityInfo activityInfo;

    //可以自动打的最小的关卡
    private int autoMinMissionId;
    //悟性
    private int kungFuDrawItemId;
    private int twinsScoreId;
    private int twinsShopItemId;
    //抽服装保留多少记录
    private int luckDrawRecordCount;
    private int pveHpItemId;
    private int pvpHpItemId;
    private int maxAttackMulValue = 1;
    private int maxBoolMulValue = 1;
    private Map<Integer,Integer> ownKungFuMap = new ConcurrentHashMap<>();
    private int bossAngerAdd;
    private int resetFreeNum;
    private String resetCost;
    private List<String> drawCostList = new ArrayList<>();
    private List<Integer> drawWeightList = new ArrayList<>();
    private List<Integer> drawExpList = new ArrayList<>();
    private List<Integer> drawAddIntegralList = new ArrayList<>();
    //抽奖必出武学列表
    private List<Integer> drawKungFuMustList = new ArrayList<>();

    private int pveMaxHp;
    private int pveHpCd;
    private int pveHpRecovery;
    private int pveHpCost;

    private String luckDrawCost = "";
    private List<Integer> luckDrawParamList = new ArrayList<>();
    private List<Integer> luckDrawAddParamList = new ArrayList<>();
    //抽奖多少次必须要有不重复的
    //多少个不重复的
    private List<Integer> luckDrawMustItemCountList = new ArrayList<>();
    //多少次
    private List<Integer> luckDrawMustDrawCountList = new ArrayList<>();


    //pvp
    private long pvpDayStartTime;
    private long pvpDayEndTime;
    //每次攻击间隔
    private long pvpAttackCd;
    //每日重置的最大体力
    private int pvpHpMax;

    private long pvpKillParam;

    private long pvpKillTimesNotice;

    //武学id 等级
    private Map<Integer, Map<Integer,TwinsKungFuConfig>> kungFuConfigMap;

    //组合id
    private Map<Integer, TwinsKungFuCombConfig> kungFuCombConfigMap;

    //章节id
    private Map<Integer, TwinsMissionConfig> missionConfigMap;

    //怪物id
    private Map<Integer, TwinsNpcConfig> npcConfigMap;

    private Map<Integer, TwinsLotteryConfig> lotteryConfigMap;

    private Map<Integer, TwinsPvpConfig> pvpConfigMap;

    private Map<Integer, TwinsMapConfig> mapConfigMap;


    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public void initConfig(Map<String, ActivityConfig> activityConfigMap,
                           Map<Integer, Map<Integer,TwinsKungFuConfig>> tempKungFuConfigMap,
                           Map<Integer, TwinsKungFuCombConfig> tempKungFuCombConfigMap,
                           Map<Integer, TwinsMissionConfig> tempMissionConfigMap,
                           Map<Integer, TwinsNpcConfig> tempNpcConfigMap,
                           Map<Integer, TwinsLotteryConfig> tempLotteryConfigMap,
                           Map<Integer, TwinsPvpConfig> tempPvpConfigMap,
                           Map<Integer, TwinsMapConfig> tempMapConfigMap) {
        List<Integer> tempInterList = new ArrayList<>();
        List<String> tempStringList = new ArrayList<>();

        String TWINS_KUNG_FU_OWN = activityConfigMap.get(eActivityConfigType.TWINS_INIT_KUNGFU_LIST.getName()).getValue();
        tempStringList = StringUtils.stringToStringList(TWINS_KUNG_FU_OWN,"\\|");
        for(String tempString : tempStringList){
            tempInterList = StringUtils.stringToIntegerList(tempString,";");
            ownKungFuMap.put(tempInterList.get(0),tempInterList.get(1));
        }

        autoMinMissionId = activityConfigMap.get(eActivityConfigType.TWINS_MISSION_AUTO_BATTLE.getName()).getIntValue();
        luckDrawCost = activityConfigMap.get(eActivityConfigType.TWINS_SKIN_EXTRACT_COST.getName()).getValue();

        kungFuDrawItemId = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_EXTRACT_ITEM_ID.getName()).getIntValue();
        twinsScoreId = activityConfigMap.get(eActivityConfigType.TWINS_SCORE_ITEM_ID.getName()).getIntValue();
        twinsShopItemId = activityConfigMap.get(eActivityConfigType.TWINS_SHOP_SCORE_ITEM_ID.getName()).getIntValue();
        pveHpItemId = activityConfigMap.get(eActivityConfigType.TWINS_ENERGY_ITEM_ID.getName()).getIntValue();
        pvpHpItemId = activityConfigMap.get(eActivityConfigType.TWINS_DARE_BOSS_ITEM_ID.getName()).getIntValue();
        pveMaxHp = activityConfigMap.get(eActivityConfigType.TWINS_ENERGY_LIMIT.getName()).getIntValue();
        pveHpCd = activityConfigMap.get(eActivityConfigType.TWINS_ENERGY_CD.getName()).getIntValue();
        pveHpRecovery = activityConfigMap.get(eActivityConfigType.TWINS_ENERGY_CD_NUM.getName()).getIntValue();
        pveHpCost = activityConfigMap.get(eActivityConfigType.TWINS_ENERGY_COST.getName()).getIntValue();
        bossAngerAdd = activityConfigMap.get(eActivityConfigType.TWINS_BOSS_FAIL_ADD_ANGER.getName()).getIntValue();
        resetFreeNum = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_RESET_FREE_NUM.getName()).getIntValue();
        resetCost = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_RESET_COST.getName()).getValue();
        resetCost = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_RESET_ITEM_ID.getName()).getIntValue() + "=" + resetCost;
        String TWINS_KUNGFU_EXTRACT_COST = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_EXTRACT_COST.getName()).getValue();
        drawCostList = StringUtils.stringToStringList(TWINS_KUNGFU_EXTRACT_COST,"\\|");
        String TWINS_KUNGFU_EXTRACT_WEIGHTS = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_EXTRACT_WEIGHTS.getName()).getValue();
        drawWeightList = StringUtils.stringToIntegerList(TWINS_KUNGFU_EXTRACT_WEIGHTS,";");
        String TWINS_KUNGFU_EXTRACT_EXP = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_EXTRACT_EXP.getName()).getValue();
        drawExpList = StringUtils.stringToIntegerList(TWINS_KUNGFU_EXTRACT_EXP,";");
        String TWINS_KUNGFU_EXTRACT_SCORE = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_EXTRACT_SCORE.getName()).getValue();
        drawAddIntegralList = StringUtils.stringToIntegerList(TWINS_KUNGFU_EXTRACT_SCORE,";");

        String TWINS_PVP_OPEN_TIME = activityConfigMap.get(eActivityConfigType.TWINS_PVP_OPEN_TIME.getName()).getValue();
        tempInterList = StringUtils.stringToIntegerList(TWINS_PVP_OPEN_TIME,";");
        pvpDayStartTime = (long)tempInterList.get(0) * DateHelper.HOUR_MILLIONS;
        pvpDayEndTime = (long)tempInterList.get(1) * DateHelper.HOUR_MILLIONS;
        String TWINS_PATRONS_CONVERT_PARAM = activityConfigMap.get(eActivityConfigType.TWINS_PATRONS_CONVERT_PARAM.getName()).getValue();
        tempInterList = StringUtils.stringToIntegerList(TWINS_PATRONS_CONVERT_PARAM,";");
        maxBoolMulValue = tempInterList.get(0);
        maxAttackMulValue = tempInterList.get(1);

        String TWINS_KUNGFU_FIRST_EXTRACT = activityConfigMap.get(eActivityConfigType.TWINS_KUNGFU_FIRST_EXTRACT.getName()).getValue();
        if(!StringUtils.isNullOrEmpty(TWINS_KUNGFU_FIRST_EXTRACT) && !TWINS_KUNGFU_FIRST_EXTRACT.equals("0")){
            drawKungFuMustList = StringUtils.stringToIntegerList(TWINS_KUNGFU_FIRST_EXTRACT,";");
        }


        kungFuConfigMap = tempKungFuConfigMap;
        kungFuCombConfigMap = tempKungFuCombConfigMap;
        missionConfigMap = tempMissionConfigMap;
        npcConfigMap = tempNpcConfigMap;
        lotteryConfigMap = tempLotteryConfigMap;
        pvpConfigMap = tempPvpConfigMap;
        mapConfigMap = tempMapConfigMap;
    }

    public void initCrossConfig(Map<String, ActivityConfig> activityConfigMap,Map<Integer, TwinsPvpConfig> tempPvpConfigMap,Map<Integer, TwinsLotteryConfig> tempLotteryConfigMap){

        List<Integer> tempInterList = new ArrayList<>();
        List<String> tempStringList = new ArrayList<>();
        String TWINS_PVP_OPEN_TIME = activityConfigMap.get(eActivityConfigType.TWINS_PVP_OPEN_TIME.getName()).getValue();
        tempInterList = StringUtils.stringToIntegerList(TWINS_PVP_OPEN_TIME,";");
        pvpDayStartTime = (long)tempInterList.get(0) * DateHelper.HOUR_MILLIONS;
        pvpDayEndTime = (long)tempInterList.get(1) * DateHelper.HOUR_MILLIONS;

        luckDrawRecordCount = activityConfigMap.get(eActivityConfigType.TWINS_LOTTERY_LOG_LIMIT.getName()).getIntValue();
        pvpAttackCd = activityConfigMap.get(eActivityConfigType.TWINS_PVP_ATTACK_CD.getName()).getLongValue();
        pvpHpMax = activityConfigMap.get(eActivityConfigType.TWINS_PVP_ENERGY_LIMIT.getName()).getIntValue();
        pvpKillParam = activityConfigMap.get(eActivityConfigType.TWINS_PVP_KILL_PARAM.getName()).getIntValue();
        pvpKillTimesNotice = activityConfigMap.get(eActivityConfigType.TWINS_PVP_STREAK_BROADCAST_LIMIT.getName()).getIntValue();


        String TWINS_SKIN_EXTRACT_LUCKY_PARAM = activityConfigMap.get(eActivityConfigType.TWINS_SKIN_EXTRACT_LUCKY_PARAM.getName()).getValue();
        luckDrawParamList = StringUtils.stringToIntegerList(TWINS_SKIN_EXTRACT_LUCKY_PARAM,";");
        String TWINS_SKIN_EXTRACT_ADD_PARAM = activityConfigMap.get(eActivityConfigType.TWINS_SKIN_EXTRACT_ADD_PARAM.getName()).getValue();
        luckDrawAddParamList = StringUtils.stringToIntegerList(TWINS_SKIN_EXTRACT_ADD_PARAM,";");
        String TWINS_SKIN_EXTRACT_REWARD_REPEAT_CONTROL = activityConfigMap.get(eActivityConfigType.TWINS_SKIN_EXTRACT_REWARD_REPEAT_CONTROL.getName()).getValue();
        tempStringList = StringUtils.stringToStringList(TWINS_SKIN_EXTRACT_REWARD_REPEAT_CONTROL,"\\|");
        for(String tempStr : tempStringList){
            tempInterList = StringUtils.stringToIntegerList(tempStr,";");
            luckDrawMustItemCountList.add(tempInterList.get(0));
            luckDrawMustDrawCountList.add(tempInterList.get(1));
        }

        pvpConfigMap = tempPvpConfigMap;

        lotteryConfigMap = tempLotteryConfigMap;

    }

    public int getAutoMinMissionId() {
        return autoMinMissionId;
    }

    public List<Integer> getDrawKungFuMustList() {
        return drawKungFuMustList;
    }

    public int getKungFuDrawItemId() {
        return kungFuDrawItemId;
    }

    public int getTwinsScoreId() {
        return twinsScoreId;
    }

    public int getTwinsShopItemId() {
        return twinsShopItemId;
    }

    public int getPveHpItemId() {
        return pveHpItemId;
    }

    public int getResetFreeNum() {
        return resetFreeNum;
    }

    public String getResetCost() {
        return resetCost;
    }

    public int getPveMaxHp() {
        return pveMaxHp;
    }

    public int getPveHpCd() {
        return pveHpCd;
    }


    public int getPveHpRecovery() {
        return pveHpRecovery;
    }

    public int getPveHpCost() {
        return pveHpCost;
    }

    public List<String> getDrawCostList() {
        return drawCostList;
    }

    public List<Integer> getDrawWeightList() {
        return drawWeightList;
    }

    public List<Integer> getDrawExpList() {
        return drawExpList;
    }

    public List<Integer> getDrawAddIntegralList() {
        return drawAddIntegralList;
    }

    public int getBossAngerAdd() {
        return bossAngerAdd;
    }

    public int getMaxBoolMulValue() {
        return maxBoolMulValue;
    }

    public int getMaxAttackMulValue() {
        return maxAttackMulValue;
    }

    public Map<Integer, Integer> getOwnKungFuMap() {
        return ownKungFuMap;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public int getBeginMissionId() {
        int minMissionId = Integer.MAX_VALUE;
        for(int missionId : missionConfigMap.keySet()){
            if(missionId < minMissionId){
                minMissionId = missionId;
            }
        }
        return minMissionId == Integer.MAX_VALUE?0:minMissionId;
    }

    public int getLastMissionId() {
        int minMissionId = Integer.MIN_VALUE;
        for(int missionId : missionConfigMap.keySet()){
            if(missionId > minMissionId){
                minMissionId = missionId;
            }
        }
        return minMissionId == Integer.MIN_VALUE?0:minMissionId;
    }

    public TwinsKungFuConfig getKungFuConfig(int kungFuId,int level) {
        if(kungFuConfigMap.containsKey(kungFuId)){
            if(kungFuConfigMap.get(kungFuId).containsKey(level)){
                return kungFuConfigMap.get(kungFuId).get(level);
            }
        }
        return null;
    }

    public Map<Integer, Map<Integer, TwinsKungFuConfig>> getKungFuConfigMap() {
        return kungFuConfigMap;
    }

    public Map<Integer, TwinsKungFuCombConfig> getKungFuCombConfigMap() {
        return kungFuCombConfigMap;
    }

    public TwinsKungFuCombConfig getKungFuCombConfig(int combId) {
        if(kungFuCombConfigMap.containsKey(combId)){
            return kungFuCombConfigMap.get(combId);
        }
        return null;
    }

    public TwinsMissionConfig getMissionConfig(int missionId) {
        if(missionConfigMap.containsKey(missionId)){
            return missionConfigMap.get(missionId);
        }
        return null;
    }

    public Map<Integer, TwinsMissionConfig> getMissionConfigMap() {
        return missionConfigMap;
    }

    public TwinsNpcConfig getNpcConfig(int bossId) {
        if(npcConfigMap.containsKey(bossId)){
            return npcConfigMap.get(bossId);
        }
        return null;
    }

    public Map<Integer, TwinsNpcConfig> getNpcConfigMap() {
        return npcConfigMap;
    }

    public Map<Integer, TwinsLotteryConfig> getLotteryConfigMap() {
        return lotteryConfigMap;
    }

    public TwinsLotteryConfig getHideLotteryConfig() {
        for(TwinsLotteryConfig twinsLotteryConfig : lotteryConfigMap.values()){
            if(twinsLotteryConfig.getIsHide() == 1){
                return twinsLotteryConfig;
            }
        }
        return null;
    }

    public Map<Integer, TwinsPvpConfig> getPvpConfigMap() {
        return pvpConfigMap;
    }

    public Map<Integer, TwinsMapConfig> getMapConfigMap() {
        return mapConfigMap;
    }

    public TwinsPvpConfig getPvpConfig(int bossId) {
        return pvpConfigMap.get(bossId);
    }



    //pvp
    public int getPvpHpMax() {
        return pvpHpMax;
    }


    public long getPvpDayStartTime() {
        return pvpDayStartTime;
    }

    public long getPvpDayEndTime() {
        return pvpDayEndTime;
    }

    public long getPvpAttackCd() {
        return pvpAttackCd;
    }

    public long getPvpKillParam() {
        return pvpKillParam;
    }

    public long getPvpKillTimesNotice() {
        return pvpKillTimesNotice;
    }

    public String getLuckDrawCost() {
        return luckDrawCost;
    }

    public List<Integer> getLuckDrawParamList() {
        return luckDrawParamList;
    }

    public List<Integer> getLuckDrawAddParamList() {
        return luckDrawAddParamList;
    }

    public List<Integer> getLuckDrawMustItemCountList() {
        return luckDrawMustItemCountList;
    }

    public List<Integer> getLuckDrawMustDrawCountList() {
        return luckDrawMustDrawCountList;
    }

    public int getLuckDrawRecordCount() {
        return luckDrawRecordCount;
    }

    public int getPvpHpItemId() {
        return pvpHpItemId;
    }
}
